<!-- 引用指标库 -->
<template>
  <a-drawer
    width="80%"
    :visible="props.visible"
    @ok="handleOk"
    @cancel="handleCancel"
    draggable
    title-align="center"
    unmountOnClose
    closable
  >
    <template #title> 实习指标库 </template>
    <div>
      <table-turn
        :table-data="getTableData"
        ref="tableRef"
        :args="args"
        row-key="name"
      >
        <a-table-column :width="80">
          <template #title> 序号 </template>
          <template #cell="{ rowIndex }">
            {{ rowIndex + 1 }}
          </template>
        </a-table-column>
        <a-table-column :width="200" data-index="name" title="指标名称">
        </a-table-column>
        <a-table-column :width="200" data-index="remark" title="指标描述">
        </a-table-column>
        <a-table-column
          :width="200"
          data-index=""
          title="评分标准"
          :headerCellStyle="{
            height: '30px'
          }"
        >
          <a-table-column
            :width="200"
            data-index="excellent"
            title="优秀A"
            :headerCellStyle="{
              height: '30px'
            }"
          >
          </a-table-column>
          <a-table-column
            :width="200"
            data-index="good"
            title="良好B"
            :headerCellStyle="{
              height: '30px'
            }"
          >
          </a-table-column>
          <a-table-column
            :width="200"
            data-index="qualified"
            title="合格C"
            :headerCellStyle="{
              height: '30px'
            }"
          >
          </a-table-column>
          <a-table-column
            :width="200"
            data-index="range"
            title="较差D"
            :headerCellStyle="{
              height: '30px'
            }"
          >
          </a-table-column>
          <a-table-column
            :width="200"
            data-index="wrong"
            title="差E"
            :headerCellStyle="{
              height: '30px'
            }"
          >
          </a-table-column>
        </a-table-column>
      </table-turn>
    </div>
    <template #footer>
      <a-space>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleOk">确认</a-button>
      </a-space>
    </template>
  </a-drawer>
</template>

<script lang="ts" setup>
import { GetBpiIndexRepeat } from '@/apis/management/performance/baseSetting/template';
import { BpiIndex } from '@/apis/management/performance/baseSetting/template/type';
import { cloneDeep } from 'lodash';
import { CheckInternshipIndex } from '@/apis/management/human/baseSetting/internshipSetting';
import CountSetting from '../CountSetting/index.vue';
import {
  PostInternshipIndex,
  PutInternshipIndex,
  GetInternshipIndex,
  DelInternshipIndex
} from '@/apis/management/human/baseSetting/internshipSetting';

const props = withDefaults(
  defineProps<{
    visible: boolean; // 是否显示对话框
    data?: any; // 传进来的数据,
  }>(),
  {}
);

const emits = defineEmits(['update:visible', 'indexEmit']);
let tableRef = ref();

// 选择器配置
const args = reactive({
  rowSelection: {
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false
  }
});

/* 储存选择的数据 */
const selectedList = computed(() => tableRef.value.selectedList);
const selectedListData = computed(() => tableRef.value.selectedListData);

const params = reactive({ name: '' });
// 获取表格数据
const getTableData = async (pageData?: any) => {
  try {
    const res = await GetInternshipIndex({
      ...pageData,
      name: params.name
    });
    res.content = res.content.filter((item: any) => {
      delete item.id;
      return item.enable === 1;
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};

const handleOk = async () => {
  emits('indexEmit', cloneDeep(selectedListData.value));
  emits('update:visible', false);
};

const handleCancel = () => {
  emits('update:visible', false);
};
</script>

<style scoped lang="less">
.icon {
  cursor: pointer;
  font-size: 20px;
}
</style>
